const { db } = require("../db/index")

module.exports = zhuce = (req, res) => {
    const userInfo = req.body;
    // db.connect()

const sql1  = `select * from user where phoneNumber=?`
db.query(sql1,[userInfo.phone], (err,results)=>{
    if(err){
    return res.cc(err)
    }
    if(results.length>0){
        return res.cc('手机号已注册，请更换手机号码')
    }

    const sql2 = `insert into user (username,password,email,phoneNumber,gender,id) values (?,?,?,?,?,newid())`
    db.query(sql2, [userInfo.nickname, userInfo.password, userInfo.email, userInfo.phone, userInfo.gender], (err, results) => {
        if (err) {
            return res.cc(err)
        }
        if (results.affectedRows != 1) {
        return res.cc('注册失败')
        } 
        res.send({
            status: 0,
            message: '注册成功',
            results: results
        })
       
    })
    
})


// db.end()
};
